home *** CD-ROM | disk | FTP | other *** search
/ Exame Informatica 139 / Exame Informatica 139.iso / Revista / Flash / Uniform Server / diskw / home / admin / www / phpMyAdmin / querywindow.php < prev    next >
Encoding:
PHP Script  |  2005-08-16  |  15.8 KB  |  287 lines

  1. <?php
  2. /* $Id: querywindow.php,v 2.18 2005/08/16 17:49:57 lem9 Exp $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4.  
  5.  
  6. /**
  7.  * Gets the variables sent to this script, retains the db name that may have
  8.  * been defined as startup option and include a core library
  9.  */
  10. require_once('./libraries/grab_globals.lib.php');
  11. if (!empty($db)) {
  12.     $db_start = $db;
  13. }
  14.  
  15.  
  16. /**
  17.  * Gets a core script and starts output buffering work
  18.  */
  19. require_once('./libraries/common.lib.php');
  20. require_once('./libraries/ob.lib.php');
  21. if ($cfg['OBGzip']) {
  22.     $ob_mode = PMA_outBufferModeGet();
  23.     if ($ob_mode) {
  24.         PMA_outBufferPre($ob_mode);
  25.     }
  26. }
  27.  
  28. require_once('./libraries/relation.lib.php');
  29. $cfgRelation = PMA_getRelationsParam();
  30.  
  31. /**
  32.  * Get the list and number of available databases.
  33.  * Skipped if no server selected: in this case no database should be displayed
  34.  * before the user choose among available ones at the welcome screen.
  35.  */
  36. if ($server > 0) {
  37.     PMA_availableDatabases(); // this function is defined in "common.lib.php"
  38. } else {
  39.     $num_dbs = 0;
  40. }
  41.  
  42. // garvin: For re-usability, moved http-headers and stylesheets
  43. // to a seperate file. It can now be included by header.inc.php,
  44. // queryframe.php, querywindow.php.
  45.  
  46. require_once('./libraries/header_http.inc.php');
  47. require_once('./libraries/header_meta_style.inc.php');
  48. ?>
  49.  
  50. <script type="text/javascript" language="javascript">
  51. <!--
  52. function query_auto_commit() {
  53.     document.sqlform.submit();
  54. }
  55.  
  56. function query_tab_commit(tab) {
  57.     document.querywindow.querydisplay_tab.value = tab;
  58.     document.querywindow.submit();
  59.     return false;
  60. }
  61.  
  62. // js form validation stuff
  63. /**/
  64. var errorMsg0   = '<?php echo str_replace('\'', '\\\'', $GLOBALS['strFormEmpty']); ?>';
  65. var errorMsg1   = '<?php echo str_replace('\'', '\\\'', $GLOBALS['strNotNumber']); ?>';
  66. var noDropDbMsg = '<?php echo((!$GLOBALS['cfg']['AllowUserDropDatabase']) ? str_replace('\'', '\\\'', $GLOBALS['strNoDropDatabases']) : ''); ?>';
  67. var confirmMsg  = '<?php echo(($GLOBALS['cfg']['Confirm']) ? str_replace('\'', '\\\'', $GLOBALS['strDoYouReally']) : ''); ?>';
  68. /**/
  69. //-->
  70. </script>
  71. <script src="libraries/functions.js" type="text/javascript" language="javascript"></script>
  72. </head>
  73.  
  74. <body bgcolor="<?php echo ($cfg['QueryFrameJS'] ? $cfg['LeftBgColor'] : $cfg['RightBgColor']); ?>">
  75. <?php
  76. if ($cfg['QueryFrameJS'] && !isset($no_js)) {
  77.     $querydisplay_tab = (isset($querydisplay_tab) ? $querydisplay_tab : $cfg['QueryWindowDefTab']);
  78.  
  79.     $tabs = array();
  80.     $tabs['sql']['icon']   = 'b_sql.png';
  81.     $tabs['sql']['text']   = $strSQL;
  82.     $tabs['sql']['link']   = '#';
  83.     $tabs['sql']['attr']   = 'onclick="javascript:query_tab_commit(\'sql\');return false;"';
  84.     $tabs['sql']['active'] = (bool) (isset($querydisplay_tab) && $querydisplay_tab == 'sql');
  85.     $tabs['import']['icon']   = 'b_import.png';
  86.     $tabs['import']['text']   = $strImportFiles;
  87.     $tabs['import']['link']   = '#';
  88.     $tabs['import']['attr']   = 'onclick="javascript:query_tab_commit(\'files\');return false;"';
  89.     $tabs['import']['active'] = (bool) (isset($querydisplay_tab) && $querydisplay_tab == 'files');
  90.     $tabs['history']['text']   = $strQuerySQLHistory;
  91.     $tabs['history']['link']   = '#';
  92.     $tabs['history']['attr']   = 'onclick="javascript:query_tab_commit(\'history\');return false;"';
  93.     $tabs['history']['active'] = (bool) (isset($querydisplay_tab) && $querydisplay_tab == 'history');
  94.  
  95.     if ($cfg['QueryWindowDefTab'] == 'full') {
  96.         $tabs['all']['text']   = $strAll;
  97.         $tabs['all']['link']   = '#';
  98.         $tabs['all']['attr']   = 'onclick="javascript:query_tab_commit(\'full\');return false;"';
  99.         $tabs['all']['active'] = (bool) (isset($querydisplay_tab) && $querydisplay_tab == 'full');
  100.     }
  101.  
  102.     echo PMA_getTabs( $tabs );
  103.     unset( $tabs );
  104. } else {
  105.     $querydisplay_tab = 'full';
  106. }
  107.  
  108. ?>
  109. <br />
  110. <?php
  111. if ($cfg['PropertiesIconic'] == true) {
  112.     // We need to copy the value or else the == 'both' check will always return true
  113.     $propicon = (string)$cfg['PropertiesIconic'];
  114.  
  115.     if ($propicon == 'both') {
  116.         $iconic_spacer = '<div class="nowrap">';
  117.     } else {
  118.         $iconic_spacer = '';
  119.     }
  120.  
  121.     $titles['Change']        = $iconic_spacer . '<img hspace="2" width="16" height="16" src="' . $pmaThemeImage . 'b_edit.png" alt="' . $strChange . '" title="' . $strChange . '" border="0" />';
  122.  
  123.     if ($propicon == 'both') {
  124.         $titles['Change']        .= ' ' . $strChange . ' </div>';
  125.     }
  126. } else {
  127.     $titles['Change']        = $strChange;
  128. }
  129.  
  130. // Hidden forms and query frame interaction stuff
  131. if ($cfg['QueryFrame'] && $cfg['QueryFrameJS']) {
  132.  
  133.     $input_query_history = array();
  134.     $sql_history = array();
  135.     $dup_sql = array();
  136.  
  137.     if (isset($query_history_latest) && isset($query_history_latest_db) && $query_history_latest != '' && $query_history_latest_db != '') {
  138.         if ($cfg['QueryHistoryDB'] && $cfgRelation['historywork']) {
  139.             PMA_setHistory((isset($query_history_latest_db) ? $query_history_latest_db : ''), (isset($query_history_latest_table) ? $query_history_latest_table : ''), $cfg['Server']['user'], $query_history_latest);
  140.         }
  141.  
  142.         $input_query_history[] = '<input type="hidden" name="query_history[]" value="' . $query_history_latest . '" />';
  143.         $input_query_history[] = '<input type="hidden" name="query_history_db[]" value="' . htmlspecialchars($query_history_latest_db) . '" />';
  144.         $input_query_history[] = '<input type="hidden" name="query_history_table[]" value="' . (isset($query_history_latest_table) ? htmlspecialchars($query_history_latest_table) : '') . '" />';
  145.  
  146.         $sql_history[] = '<li>'
  147.                        . '<a href="#" onclick="document.querywindow.querydisplay_tab.value = \'' . (isset($querydisplay_tab) && $querydisplay_tab != 'full' ? 'sql' : 'full') . '\'; document.querywindow.query_history_latest.value = \'' . preg_replace('/(\n)/i', ' ', addslashes(htmlspecialchars($query_history_latest))) . '\'; document.querywindow.auto_commit.value = \'false\'; document.querywindow.db.value = \'' . htmlspecialchars($query_history_latest_db) . '\'; document.querywindow.query_history_latest_db.value = \'' . htmlspecialchars($query_history_latest_db) . '\'; document.querywindow.table.value = \'' . (isset($query_history_latest_table) ? htmlspecialchars($query_history_latest_table) : '') . '\'; document.querywindow.query_history_latest_table.value = \'' . (isset($query_history_latest_table) ? htmlspecialchars($query_history_latest_table) : '') . '\'; document.querywindow.submit(); return false;">' . $titles['Change'] . '</a>'
  148.                        . ' <a href="#" onclick="document.querywindow.querydisplay_tab.value = \'' . (isset($querydisplay_tab) && $querydisplay_tab != 'full' ? 'sql' : 'full') . '\'; document.querywindow.query_history_latest.value = \'' . preg_replace('/(\n)/i', ' ', addslashes(htmlspecialchars($query_history_latest))) . '\'; document.querywindow.auto_commit.value = \'true\'; document.querywindow.db.value = \'' . htmlspecialchars($query_history_latest_db) . '\'; document.querywindow.query_history_latest_db.value = \'' . htmlspecialchars($query_history_latest_db) . '\'; document.querywindow.table.value = \'' . (isset($query_history_latest_table) ? htmlspecialchars($query_history_latest_table) : '') . '\'; document.querywindow.query_history_latest_table.value = \'' . (isset($query_history_latest_table) ? htmlspecialchars($query_history_latest_table) : '') . '\'; document.querywindow.submit(); return false;">[' . htmlspecialchars($query_history_latest_db) . '] ' . urldecode($query_history_latest) . '</a>'
  149.                        . '</li>' . "\n";
  150.  
  151.         $sql_query = urldecode($query_history_latest);
  152.         $db = $query_history_latest_db;
  153.         $table = $query_history_latest_table;
  154.         $dup_sql[$query_history_latest] = true;
  155.     } elseif (isset($query_history_latest) && $query_history_latest != '') {
  156.         $sql_query = urldecode($query_history_latest);
  157.     }
  158.  
  159.     if (isset($sql_query)) {
  160.         $show_query = 1;
  161.     }
  162.  
  163.     if ($cfg['QueryHistoryDB'] && $cfgRelation['historywork']) {
  164.  
  165.         $temp_history = PMA_getHistory($cfg['Server']['user']);
  166.         if (is_array($temp_history) && count($temp_history) > 0) {
  167.             foreach ($temp_history AS $history_nr => $history_array) {
  168.                 if (!isset($dup_sql[$history_array['sqlquery']])) {
  169.                     $sql_history[] = '<li>'
  170.                                    . '<a href="#" onclick="document.querywindow.querydisplay_tab.value = \'' . (isset($querydisplay_tab) && $querydisplay_tab != 'full' ? 'sql' : 'full') . '\'; document.querywindow.query_history_latest.value = \'' . preg_replace('/(\n)/i', ' ', addslashes(htmlspecialchars($history_array['sqlquery']))) . '\'; document.querywindow.auto_commit.value = \'false\'; document.querywindow.db.value = \'' . htmlspecialchars($history_array['db']) . '\'; document.querywindow.query_history_latest_db.value = \'' . htmlspecialchars($history_array['db']) . '\'; document.querywindow.table.value = \'' . (isset($history_array['table']) ? htmlspecialchars($history_array['table']) : '') . '\'; document.querywindow.query_history_latest_table.value = \'' . (isset($history_array['table']) ? htmlspecialchars($history_array['table']) : '') . '\'; document.querywindow.submit(); return false;">' . $titles['Change'] . '</a>'
  171.                                    . '<a href="#" onclick="document.querywindow.querydisplay_tab.value = \'' . (isset($querydisplay_tab) && $querydisplay_tab != 'full' ? 'sql' : 'full') . '\'; document.querywindow.query_history_latest.value = \'' . preg_replace('/(\n)/i', ' ', addslashes(htmlspecialchars($history_array['sqlquery']))) . '\'; document.querywindow.auto_commit.value = \'true\'; document.querywindow.db.value = \'' . htmlspecialchars($history_array['db']) . '\'; document.querywindow.query_history_latest_db.value = \'' . htmlspecialchars($history_array['db']) . '\'; document.querywindow.table.value = \'' . (isset($history_array['table']) ? htmlspecialchars($history_array['table']) : '') . '\'; document.querywindow.query_history_latest_table.value = \'' . (isset($history_array['table']) ? htmlspecialchars($history_array['table']) : '') . '\'; document.querywindow.submit(); return false;">[' . htmlspecialchars($history_array['db']) . '] ' . urldecode($history_array['sqlquery']) . '</a>'
  172.                                    . '</li>' . "\n";
  173.                     $dup_sql[$history_array['sqlquery']] = true;
  174.                 }
  175.             }
  176.         }
  177.  
  178.     } else {
  179.  
  180.         if (isset($query_history) && is_array($query_history)) {
  181.             $current_index = count($query_history);
  182.             foreach ($query_history AS $query_no => $query_sql) {
  183.                 if (!isset($dup_sql[$query_sql])) {
  184.  
  185.                     $input_query_history[] = '<input type="hidden" name="query_history[]" value="' . $query_sql . '" />';
  186.                     $input_query_history[] = '<input type="hidden" name="query_history_db[]" value="' . htmlspecialchars($query_history_db[$query_no]) . '" />';
  187.                     $input_query_history[] = '<input type="hidden" name="query_history_table[]" value="' . (isset($query_history_table[$query_no]) ? htmlspecialchars($query_history_table[$query_no]) : '') . '" />';
  188.  
  189.                     $sql_history[] = '<li>'
  190.                                    . '<a href="#" onclick="document.querywindow.querydisplay_tab.value = \'' . (isset($querydisplay_tab) && $querydisplay_tab != 'full' ? 'sql' : 'full') . '\'; document.querywindow.query_history_latest.value = \'' . htmlspecialchars($query_sql) . '\'; document.querywindow.auto_commit.value = \'false\'; document.querywindow.db.value = \'' . htmlspecialchars($query_history_db[$query_no]) . '\'; document.querywindow.query_history_latest_db.value = \'' . htmlspecialchars($query_history_db[$query_no]) . '\'; document.querywindow.table.value = \'' . (isset($query_history_table[$query_no]) ? htmlspecialchars($query_history_table[$query_no]) : '') . '\'; document.querywindow.query_history_latest_table.value = \'' . (isset($query_history_table[$query_no]) ? htmlspecialchars($query_history_table[$query_no]) : '') . '\'; document.querywindow.submit(); return false;">' . $titles['Change'] . '</a>'
  191.                                    . '<a href="#" onclick="document.querywindow.querydisplay_tab.value = \'' . (isset($querydisplay_tab) && $querydisplay_tab != 'full' ? 'sql' : 'full') . '\'; document.querywindow.query_history_latest.value = \'' . htmlspecialchars($query_sql) . '\'; document.querywindow.auto_commit.value = \'true\'; document.querywindow.db.value = \'' . htmlspecialchars($query_history_db[$query_no]) . '\'; document.querywindow.query_history_latest_db.value = \'' . htmlspecialchars($query_history_db[$query_no]) . '\'; document.querywindow.table.value = \'' . (isset($query_history_table[$query_no]) ? htmlspecialchars($query_history_table[$query_no]) : '') . '\'; document.querywindow.query_history_latest_table.value = \'' . (isset($query_history_table[$query_no]) ? htmlspecialchars($query_history_table[$query_no]) : '') . '\'; document.querywindow.submit(); return false;">[' . htmlspecialchars($query_history_db[$query_no]) . '] ' . urldecode($query_sql) . '</a>'
  192.                                    . '</li>' . "\n";
  193.                     $dup_sql[$query_sql] = true;
  194.                 } // end if check if this item exists
  195.             } // end while print history
  196.         } // end if history exists
  197.  
  198.     } // end if DB-based history
  199. }
  200.  
  201. $url_query = PMA_generate_common_url(isset($db) ? $db : '', isset($table) ? $table : '');
  202. if (!isset($goto)) {
  203.     $goto = '';
  204. }
  205.  
  206. require_once './libraries/bookmark.lib.php';
  207. $is_inside_querywindow = TRUE;
  208. require './tbl_query_box.php';
  209.  
  210. // Hidden forms and query frame interaction stuff
  211. if ($cfg['QueryFrame'] && $cfg['QueryFrameJS']) {
  212.     if (isset($auto_commit) && $auto_commit == 'true') {
  213.     ?>
  214.         <script type="text/javascript" language="javascript">
  215.         query_auto_commit();
  216.         </script>
  217.     <?php
  218.     }
  219.  
  220.     if (isset($sql_history) && isset($querydisplay_tab) && ($querydisplay_tab == 'history' || $querydisplay_tab == 'full') && is_array($sql_history) && count($sql_history) > 0) {
  221.     ?>
  222.         <?php echo $strQuerySQLHistory . ':<br /><ul>' . implode('', $sql_history) . '</ul>'; ?>
  223.     <?php
  224.     }
  225. ?>
  226. <form action="querywindow.php" method="post" name="querywindow">
  227. <?php
  228.     echo PMA_generate_common_hidden_inputs('', '');
  229.     if (count($input_query_history) > 0) {
  230.         echo implode("\n", $input_query_history);
  231.     }
  232. ?>
  233.     <input type="hidden" name="db" value="<?php echo (empty($db) ? '' : htmlspecialchars($db)); ?>" />
  234.     <input type="hidden" name="table" value="<?php echo (empty($table) ? '' : htmlspecialchars($table)); ?>" />
  235.  
  236.     <input type="hidden" name="query_history_latest" value="" />
  237.     <input type="hidden" name="query_history_latest_db" value="" />
  238.     <input type="hidden" name="query_history_latest_table" value="" />
  239.  
  240.     <input type="hidden" name="previous_db" value="<?php echo htmlspecialchars($db); ?>" />
  241.  
  242.     <input type="hidden" name="auto_commit" value="false" />
  243.     <input type="hidden" name="querydisplay_tab" value="<?php echo $querydisplay_tab; ?>" />
  244. </form>
  245.  
  246. <?php
  247. }
  248.  
  249. $tmp_querydisplay_tab =  (isset($querydisplay_tab) ? $querydisplay_tab : $cfg['QueryWindowDefTab']);
  250. if ($tmp_querydisplay_tab == 'sql' || $tmp_querydisplay_tab == $cfg['QueryWindowDefTab']) {
  251. ?>
  252. <script type="text/jscript" language="javascript">
  253. <!--
  254.     if (document.getElementById && typeof(document.getElementById('sqlcontainer'))!='undefined') {
  255.         var newWidth  = document.getElementById('sqlcontainer').offsetWidth + 40;
  256.         var newHeight = document.getElementById('sqlcontainer').offsetHeight + 100;
  257.         self.resizeTo(newWidth, newHeight);
  258.     }
  259. //-->
  260. </script>
  261. <?php
  262. }
  263. ?>
  264. </body>
  265. </html>
  266.  
  267. <?php
  268. /**
  269.  * Close MySql connections
  270.  */
  271. if (isset($dbh) && $dbh) {
  272.     PMA_DBI_close($dbh);
  273. }
  274. if (isset($userlink) && $userlink) {
  275.     PMA_DBI_close($userlink);
  276. }
  277.  
  278.  
  279. /**
  280.  * Sends bufferized data
  281.  */
  282. if (isset($cfg['OBGzip']) && $cfg['OBGzip']
  283.     && isset($ob_mode) && $ob_mode) {
  284.      PMA_outBufferPost($ob_mode);
  285. }
  286. ?>
  287.